package com.lsj.controller;

import com.lsj.core.response.CommonResult;
import com.lsj.core.util.ExceptionHelperUtil;
import com.lsj.dto.sys.OrgDto;
import com.lsj.dto.sys.UserOrgDto;
import com.lsj.service.UserOrgService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:lin.sj
 * @Data:2021/7/8 19:28
 * @Desc: 用户与角色处理
 */
@RestController
@RequestMapping("/sys_user_org")
@Api(tags = "用户与组织机构处理")
public class UserOrgController {

    @Autowired
    UserOrgService userOrgService;

    @PostMapping("/updateOrgForUser")
    @ApiOperation(value = "更新用户与角色关系")
    public CommonResult updateRoleForUser(@RequestBody @Validated UserOrgDto dto){
        userOrgService.updateOrgForUser(dto);
        return CommonResult.success();
    }

    @GetMapping("/findOrgByUserId")
    public CommonResult findOrgByUserId(@RequestParam("userId") Long userId){
        ExceptionHelperUtil.nullObjException(userId,"用户主键不能为空");
        OrgDto orgDto = userOrgService.findOrgByUserId(userId);
        return CommonResult.success(orgDto);
    }
}
